import hashlib
import random


# sha256加密
from django.core.mail import send_mail

from shiyanloutower.settings import FROM_EMAIL


def encrypt(raw):
    sha256 = hashlib.sha256()
    sha256.update(raw.encode('utf-8'))
    return sha256.hexdigest()


# 验证码
def create_verify_code(num=6):
    base_list = [str(i) for i in range(10)]
    new_list = random.sample(base_list, num)

    return ''.join(new_list)

# 邮箱
def Chuan_Email(code, email):
    return send_mail(
        '[实验楼]用户注册验证码',  # 邮件标题
        f'验证码:{code}---当前验证码五分钟之内有效',  # 邮件正文 html
        FROM_EMAIL,  # 发送方地址 settings.FROM_EMAIL
        [email],  # 收件方地址
    )

